home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JMenuBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  6.8 KB  |  285 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Graphics;
  6. import java.awt.Insets;
  7. import java.awt.event.KeyEvent;
  8. import java.awt.event.MouseEvent;
  9. import java.io.IOException;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.Serializable;
  13. import java.util.Vector;
  14. import javax.accessibility.Accessible;
  15. import javax.accessibility.AccessibleContext;
  16. import javax.swing.plaf.MenuBarUI;
  17.  
  18. public class JMenuBar extends JComponent implements Accessible, MenuElement {
  19.    private static final String uiClassID = "MenuBarUI";
  20.    private transient SingleSelectionModel selectionModel;
  21.    private boolean paintBorder = true;
  22.    private Insets margin = null;
  23.  
  24.    public JMenuBar() {
  25.       this.setSelectionModel(new DefaultSingleSelectionModel());
  26.       this.updateUI();
  27.    }
  28.  
  29.    public JMenu add(JMenu var1) {
  30.       super.add(var1);
  31.       return var1;
  32.    }
  33.  
  34.    public void addNotify() {
  35.       super.addNotify();
  36.       KeyboardManager.getCurrentManager().registerMenuBar(this);
  37.    }
  38.  
  39.    JComponent.KeyboardBinding bindingForKeyStroke(KeyStroke var1, int var2) {
  40.       JComponent.KeyboardBinding var3 = super.bindingForKeyStroke(var1, var2);
  41.       if (var3 != null) {
  42.          return var3;
  43.       } else {
  44.          Component[] var5 = ((Container)this).getComponents();
  45.  
  46.          for(int var4 = 0; var4 < var5.length; ++var4) {
  47.             if (var5[var4] instanceof JMenu) {
  48.                var3 = bindingForKeyStrokeRecursive(var5[var4], var1, var2);
  49.             }
  50.  
  51.             if (var3 != null) {
  52.                return var3;
  53.             }
  54.          }
  55.  
  56.          return null;
  57.       }
  58.    }
  59.  
  60.    static JComponent.KeyboardBinding bindingForKeyStrokeRecursive(Component var0, KeyStroke var1, int var2) {
  61.       JComponent.KeyboardBinding var3 = null;
  62.       if (var0 == null) {
  63.          return null;
  64.       } else {
  65.          if (var0 instanceof JComponent) {
  66.             var3 = ((JComponent)var0).bindingForKeyStroke(var1, var2);
  67.             if (var3 != null) {
  68.                return var3;
  69.             }
  70.          }
  71.  
  72.          if (var0 instanceof JMenu) {
  73.             JMenu var4 = (JMenu)var0;
  74.             Component[] var6 = var4.getMenuComponents();
  75.             if (var6 != null) {
  76.                for(int var5 = 0; var5 < var6.length; ++var5) {
  77.                   if (var6[var5] instanceof JMenuItem) {
  78.                      var3 = bindingForKeyStrokeRecursive(var6[var5], var1, var2);
  79.                   }
  80.  
  81.                   if (var3 != null) {
  82.                      return var3;
  83.                   }
  84.                }
  85.             }
  86.          }
  87.  
  88.          return var3;
  89.       }
  90.    }
  91.  
  92.    public AccessibleContext getAccessibleContext() {
  93.       if (super.accessibleContext == null) {
  94.          super.accessibleContext = new AccessibleJMenuBar(this);
  95.       }
  96.  
  97.       return super.accessibleContext;
  98.    }
  99.  
  100.    public Component getComponent() {
  101.       return this;
  102.    }
  103.  
  104.    public Component getComponentAtIndex(int var1) {
  105.       return ((Container)this).getComponent(var1);
  106.    }
  107.  
  108.    public int getComponentIndex(Component var1) {
  109.       int var2 = ((Container)this).getComponentCount();
  110.       Component[] var3 = ((Container)this).getComponents();
  111.  
  112.       for(int var4 = 0; var4 < var2; ++var4) {
  113.          Component var5 = var3[var4];
  114.          if (var5 == var1) {
  115.             return var4;
  116.          }
  117.       }
  118.  
  119.       return -1;
  120.    }
  121.  
  122.    public JMenu getHelpMenu() {
  123.       throw new Error("getHelpMenu() not yet implemented.");
  124.    }
  125.  
  126.    public Insets getMargin() {
  127.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  128.    }
  129.  
  130.    public JMenu getMenu(int var1) {
  131.       Component var2 = this.getComponentAtIndex(var1);
  132.       return var2 instanceof JMenu ? (JMenu)var2 : null;
  133.    }
  134.  
  135.    public int getMenuCount() {
  136.       return ((Container)this).getComponentCount();
  137.    }
  138.  
  139.    public SingleSelectionModel getSelectionModel() {
  140.       return this.selectionModel;
  141.    }
  142.  
  143.    public MenuElement[] getSubElements() {
  144.       Vector var2 = new Vector();
  145.       int var3 = ((Container)this).getComponentCount();
  146.  
  147.       for(int var4 = 0; var4 < var3; ++var4) {
  148.          Component var5 = ((Container)this).getComponent(var4);
  149.          if (var5 instanceof MenuElement) {
  150.             var2.addElement(var5);
  151.          }
  152.       }
  153.  
  154.       MenuElement[] var1 = new MenuElement[var2.size()];
  155.       int var7 = 0;
  156.  
  157.       for(int var6 = var2.size(); var7 < var6; ++var7) {
  158.          var1[var7] = (MenuElement)var2.elementAt(var7);
  159.       }
  160.  
  161.       return var1;
  162.    }
  163.  
  164.    public MenuBarUI getUI() {
  165.       return (MenuBarUI)super.ui;
  166.    }
  167.  
  168.    public String getUIClassID() {
  169.       return "MenuBarUI";
  170.    }
  171.  
  172.    public boolean isBorderPainted() {
  173.       return this.paintBorder;
  174.    }
  175.  
  176.    public boolean isManagingFocus() {
  177.       return true;
  178.    }
  179.  
  180.    public boolean isSelected() {
  181.       return this.selectionModel.isSelected();
  182.    }
  183.  
  184.    public void menuSelectionChanged(boolean var1) {
  185.    }
  186.  
  187.    protected void paintBorder(Graphics var1) {
  188.       if (this.isBorderPainted()) {
  189.          super.paintBorder(var1);
  190.       }
  191.  
  192.    }
  193.  
  194.    protected String paramString() {
  195.       String var1 = this.paintBorder ? "true" : "false";
  196.       String var2 = this.margin != null ? this.margin.toString() : "";
  197.       return super.paramString() + ",margin=" + var2 + ",paintBorder=" + var1;
  198.    }
  199.  
  200.    public void processKeyEvent(KeyEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  201.    }
  202.  
  203.    public void processMouseEvent(MouseEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  204.    }
  205.  
  206.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  207.       var1.defaultReadObject();
  208.       Object[] var2 = var1.readObject();
  209.  
  210.       for(int var3 = 0; var3 < var2.length && var2[var3] != null; var3 += 2) {
  211.          if (var2[var3].equals("selectionModel")) {
  212.             this.selectionModel = (SingleSelectionModel)var2[var3 + 1];
  213.          }
  214.       }
  215.  
  216.       if (super.ui != null && this.getUIClassID().equals("MenuBarUI")) {
  217.          super.ui.installUI(this);
  218.       }
  219.  
  220.    }
  221.  
  222.    public void removeNotify() {
  223.       super.removeNotify();
  224.       KeyboardManager.getCurrentManager().unregisterMenuBar(this);
  225.    }
  226.  
  227.    public void setBorderPainted(boolean var1) {
  228.       boolean var2 = this.paintBorder;
  229.       this.paintBorder = var1;
  230.       ((JComponent)this).firePropertyChange("borderPainted", var2, this.paintBorder);
  231.       if (var1 != var2) {
  232.          ((JComponent)this).revalidate();
  233.          ((Component)this).repaint();
  234.       }
  235.  
  236.    }
  237.  
  238.    public void setHelpMenu(JMenu var1) {
  239.       throw new Error("setHelpMenu() not yet implemented.");
  240.    }
  241.  
  242.    public void setMargin(Insets var1) {
  243.       Insets var2 = this.margin;
  244.       this.margin = var1;
  245.       ((JComponent)this).firePropertyChange("margin", var2, var1);
  246.       if (var2 == null || !var1.equals(var2)) {
  247.          ((JComponent)this).revalidate();
  248.          ((Component)this).repaint();
  249.       }
  250.  
  251.    }
  252.  
  253.    public void setSelected(Component var1) {
  254.       SingleSelectionModel var2 = this.getSelectionModel();
  255.       int var3 = this.getComponentIndex(var1);
  256.       var2.setSelectedIndex(var3);
  257.    }
  258.  
  259.    public void setSelectionModel(SingleSelectionModel var1) {
  260.       SingleSelectionModel var2 = this.selectionModel;
  261.       this.selectionModel = var1;
  262.       ((JComponent)this).firePropertyChange("selectionModel", var2, this.selectionModel);
  263.    }
  264.  
  265.    public void setUI(MenuBarUI var1) {
  266.       super.setUI(var1);
  267.    }
  268.  
  269.    public void updateUI() {
  270.       this.setUI((MenuBarUI)UIManager.getUI(this));
  271.    }
  272.  
  273.    private void writeObject(ObjectOutputStream var1) throws IOException {
  274.       var1.defaultWriteObject();
  275.       Object[] var2 = new Object[4];
  276.       int var3 = 0;
  277.       if (this.selectionModel instanceof Serializable) {
  278.          var2[var3++] = "selectionModel";
  279.          var2[var3++] = this.selectionModel;
  280.       }
  281.  
  282.       var1.writeObject(var2);
  283.    }
  284. }
  285.